import {Component, Inject} from '@angular/core';
import {ChatExampleData} from './data/chat-example-data';

import {UsersService} from './user/users.service';
import {ThreadsService} from './thread/threads.service';
import {MessagesService} from './message/messages.service';
import {ChatProductData} from './data/chat-product-data';
import {ChatHttpComponent} from './chat-http/chat-http.component';
import {Http} from '@angular/http';
import {Message} from './message/message.model';
import {Observable} from 'rxjs/Observable';
import {User} from './user/user.model';

const me: User = new User('Juliet', 'assets/images/avatars/female-avatar-1.png');

@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})

export class AppComponent {
  dataSource: Observable<any>;
  initialMessages: Array<any>;

  constructor(private http: Http,
              public messagesService: MessagesService,
              public threadsService: ThreadsService,
              public usersService: UsersService) {
    // ChatExampleData.init(messagesService, threadsService, usersService);
    this.dataSource = this.http.get('/app/getmessages').map((res) => res.json());
    messagesService.messages.subscribe(() => ({}));
    usersService.setCurrentUser(me);
    this.dataSource.subscribe((data) => data.map((message: Message) =>
      messagesService.addMessage(message)));
  }
}
